package cn.itwen.star.graph.comfyui.client.handle;

import cn.itwen.star.graph.comfyui.client.pojo.MessageBase;
import cn.itwen.star.graph.core.service.ComfyuiMessageService;
import cn.itwen.star.graph.core.service.WsNoticeService;
import com.alibaba.fastjson2.JSON;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.socket.TextMessage;
import org.springframework.web.socket.WebSocketSession;
import org.springframework.web.socket.handler.TextWebSocketHandler;

@Slf4j
public class ComfyuiMessageHandler extends TextWebSocketHandler {

    @Autowired
    private ComfyuiMessageService comfyuiMessageService;

    @Override
    protected void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception {
        String playload = message.getPayload();
        log.info("接收到消息：{}",playload);
        MessageBase messageBase = JSON.parseObject(playload, MessageBase.class);
        comfyuiMessageService.handleMessage(messageBase);
    }

    @Override
    public void afterConnectionEstablished(WebSocketSession session) throws Exception {
        System.out.println("=========================连接成功"+ session.getId());
    }


}
